<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title></title>
<link href="houtai/css/style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="houtai/js/main.js"></script>
<script type="text/javascript">

function fuclick(f,fi){
	
		var arr=document.getElementsByName(fi);
			
			   for(var i=0;i<arr.length;i++){
			   			arr[i].checked=f.checked;
				}
	
	}

	function ziclick(z,fi){
		var ar=document.getElementsByName(fi);
			
				var flag=false;
				for(var i=1;i<ar.length;i++){
				 if(ar[i].checked){
				 	flag=true;
				    }
				}
				ar[0].checked=flag;
	}

	var xmlhttp;
	function ckrolname(){
		
		var rolname=document.getElementById("rolName").value;
		if(rolname==""){
			document.getElementById("spnrolname").innerHTML="请输入角色名";
			document.getElementById("spnrolname").style.color="red";
			return false;
		}
		document.getElementById("spnrolname").innerHTML="";
	
		xmlhttp=new XMLHttpRequest();
		xmlhttp.onreadystatechange=huirolname;
		xmlhttp.open("get", "RoleServlet?param=ajaxrolename&rolname="+rolname+"&time="+new Date().getTime(), true);
		xmlhttp.send(null);
		
	}
	function huirolname(){
		if(xmlhttp.readyState==4&&xmlhttp.status==200){
			var txt=xmlhttp.responseText;
			document.getElementById("spnrolname").innerHTML=txt;
			if(txt=="√"){
				document.getElementById("spnrolname").style.color="green";
			}else{
				document.getElementById("spnrolname").style.color="red";
			}
		}
	}

	
	function ckrname(){
		var rolname=document.getElementById("rolName").value;
		if(rolname==""){
			document.getElementById("spnrolname").innerHTML="请输入角色名";
			document.getElementById("spnrolname").style.color="red";
			return false;
		}
		document.getElementById("spnrolname").innerHTML="";
	
		return true;
	}
	
	function ckspan(){
		var spn=document.getElementById("spnrolname").innerHTML;
		if(spn=="角色名已存在"){
			alert("角色名已存在");
			return false;
		}
		return true;
	}
	
	function ckremark(){
		if(document.getElementById("rolRemark").value==""){
			document.getElementById("s1").innerHTML="备注不能为空";
			document.getElementById("s1").style.color="red";
			return false;
		}
		document.getElementById("s1").innerHTML="";
		return true;
	}
	
	function chesub(){

		if(ckspan()&&ckrname()&&ckremark()){
			if(confirm("确定提交吗?")){
				document.getElementById("form7").submit();
				return true;
			}
		}else{
			return false;
		}
	}

</script>
</head>
<body>
<table width="100%" height="100%" border="0" cellspacing="0" cellpadding="3">
  <tr>
    <td style="height:25px; background-color:#f3f3f3; font-weight:bold" valign="top">&nbsp;&nbsp;&nbsp;&nbsp;当前位置：
    <img src="houtai/images/arrow.gif" align="absmiddle">&nbsp;&nbsp;soda创业教育平台&nbsp;&nbsp;
    <img src="houtai/images/arrow.gif" align="absmiddle">&nbsp;&nbsp;后台管理&nbsp;&nbsp;
    <img src="houtai/images/arrow.gif" align="absmiddle">&nbsp;&nbsp;角色管理
    </td>
  </tr>
  <tr>
    <td style="height:34px; background-image:url(houtai/images/main_header.gif); border-bottom:1px solid #cfd8e0; padding:0px">
      <table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td width="20" height="34"><img src="houtai/images/main_headerL.gif" width="20" height="34"></td>
          <td style="color:#90c8e8;"><img src="houtai/images/icon_card.gif" width="16" height="16" align="absmiddle">&nbsp;&nbsp;<strong>添加角色</strong></td>
          <td align="right" class="white" style="padding-right:20px">
          <a  class="barBtn" onClick="javascript:history.go(-1);"><img src="houtai/images/btn_left.gif" align="absmiddle"> 后退</a>
          <a  class="barBtn" onClick="javascript:history.go(+1);"><img src="houtai/images/btn_right.gif" align="absmiddle"> 前进</a>
          <a href="<%=request.getContextPath() %>/RoleServlet?param=addRole" class="barBtn"><img src="houtai/images/btn_refresh.gif" align="absmiddle"> 刷新</a>
          </td>
        </tr>
    </table></td>
  </tr>
  <tr>
    <td height="100%" valign="top">
    <div style="overflow:auto;height:500px; width:100%">
    <form id="form7" action="<%=request.getContextPath() %>/RoleServlet?param=addRoleInfo" method="post">
      <table width="100%" border="0" cellpadding="3" cellspacing="1" class="table1">
        <TR>
          <th width="20%" align="center">角色名</th>
          <TD class="BGCgray"><input type="text" name="rolName" id="rolName" onblur="ckrolname()"  /><span  id="spnrolname"></span></TD>
        </TR>
        <TR>
          <th align="center">对应菜单</th>
          <TD class="BGCgray">
			<ul>
			
			
				<c:forEach items="${requestScope.fmenus }" var="fmenu">
				<c:if test="${fmenu.fmeDelete==1 }">
            	<li><input type="checkbox" name="fu${fmenu.fmeId }" onclick="fuclick(this,'fu${fmenu.fmeId}')" value="${fmenu.fmeId }"/>${fmenu.fmeName }
                	<ul>
                	
                	<c:forEach items="${fmenu.menus }" var="menu">
                	<c:if test="${menu.menDelete==1 }">
                   	<li><input type="checkbox" name="fu${fmenu.fmeId }" onclick="ziclick(this,'fu${fmenu.fmeId}')" value="${menu.menId }"/>${menu.menName }</li>
                   	</c:if>
                   	</c:forEach>
                   	
        	    	
                    </ul>
                </li>
                </c:if>
                </c:forEach>
                
              

            </ul>
          </TD>
        </TR>
        <TR>
          <th align="center">启用状态</th>
          <TD class="BGCgray">
          <input type="radio" name="rolState" value="1" checked="checked" />启用
          <input type="radio" name="rolState" value="0" />禁用
          </TD>
        </TR>
        <TR>
          <th align="center"><span class="BGCgray">备注</span></th>
          <TD class="BGCgray">
          	<textarea name="rolRemark" id="rolRemark" onblur="ckremark()">暂无
            </textarea><span id="s1"></span>
          </TD>
        </TR>
      </table>
        </form>
      <div style="width:100%; text-align:center; padding:5px">
        <BUTTON style="HEIGHT:25px" onClick="return chesub();"><img src="houtai/images/btn_save.gif" width="16" height="16" align="absmiddle"> 保存</BUTTON><BUTTON style="HEIGHT:25px" onClick="history.go(-1);"><img src="houtai/images/btn_back.gif" width="16" height="16" align="absmiddle"> 返回</BUTTON>
      </div>
    </div>
  
  </td>
  </tr>
</table>
</body>
</html>